<!DOCTYPE html>
<html lang="en" style="height: 100%;">

<head>
    <meta charset="UTF-8">
    <title>代码分析查看器</title>
    <link rel="stylesheet" href="css/neo4jd3.min.css">
    <link rel="stylesheet" href="css/rightMenu.css">
    <script src="./lib/markdown/showdown.min.js"></script>
    <!-- Add Prism.js for syntax highlighting -->
    <link href="./lib/markdown/prism-okaidia.min.css" rel="stylesheet" />
    <script src="./lib/markdown/prism.min.js"></script>
    <script src="./lib/markdown/prism-csharp.min.js"></script>
    <style>
        .container {
            display: flex;
            height: calc(100% - 65px);
            width: calc(100% - 5px);
        }

        #fileList {
            width: 300px;
            overflow-y: auto;
            border-right: 1px solid #ddd;
            padding: 10px;
        }

        #contentView {
            flex: 1;
            display: flex;
            flex-direction: column;
            padding: 0;
            width: 65%;
        }

        .split-pane {
            font-size: 0.8em;
            float: inline-start;
        }

        .topPanel {
            display: flex;
            flex-direction: row;
            height: 70%;
        }
        .leftPane{
            padding: 20px;
            overflow: auto;
        }

        .vertical-splitter {
            width: 5px;
            background-color: #ddd;
            cursor: col-resize;
            position: relative;
            z-index: 10;
            height: 100%;
            float: inline-start;
        }

        .splitter {
            height: 5px;
            background-color: #ddd;
            cursor: row-resize;
            position: relative;
        }

        .splitter:hover, .vertical-splitter:hover {
            background-color: #3498db;
        }

        .file-item {
            padding: 8px;
            cursor: pointer;
            border-radius: 4px;
            margin-bottom: 5px;
            transition: background-color 0.3s ease; /* 添加过渡效果 */
        }

        .file-item:hover {
            background-color: #f5f5f5; /* 悬停时的背景颜色 */
        }

        .file-item.active {
            background-color: #3498db;
            color: white;
        }
        .bottom-code{
            overflow: scroll;
            width: 100%;
            height: 31%;
        }

        /* Add some padding for code blocks */
        pre[class*="language-"] {
            padding: 1em;
            margin: 0;
            overflow: auto;
            background: #2d2d2d;
            height: calc(100% - 20%px);
        }
        code{
            font-family: system-ui;
            color: #2622c7;
            padding: 4px;
        }
        .score{
            font-family: 'Courier New', Courier, monospace;
            font-size: 33px;
            font-weight: bold;
            color: #c7520b;
        }
    </style>
</head>

<body style="height: 100%; margin: 0; font-family: 'Helvetica Neue', Arial, sans-serif; background-color: #f5f7fa;"
    onload="onload()">
    <header
        style="background-color: #2c3e50; color: white; padding: 15px 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
        <h1 style="margin: 0; font-size: 24px; display: inline-block;">代码分析查看器</h1>
    </header>

    <div class="container">
        <div id="fileList"></div>
        <div id="contentView">
            <div class="topPanel">
                <div id="leftPane" class="split-pane leftPane" style="font-size: 0.8em; width: 50%;"></div>
                <div class="vertical-splitter"></div>
                <div id="rightPane" class="split-pane" style="font-size: 0.8em; width: 50%;">
                    <iframe src="localMap.html?style=simple" id="knMap" style="width:100%;height: 100%;" border="0"></iframe>
                </div>
            </div>
            <div id="splitter" class="splitter"></div>
            <div id="bottomPane" class="split-pane bottom-code" style="font-size: 0.6em;"></div>
        </div>
    </div>

    <script>
        var allFileList = {};
        async function onload() {
            try {
                const response = await fetch('assets/codeStruct/index.json');
                const files = await response.json();
                renderFileList(files);
            } catch (error) {
                console.error('Error loading index.json:', error);
            }
        }

        function renderFileList(files) {
            for (var i = 0; i < files.length; i++) {
                allFileList[files[i].fileName] = files[i];
            }
            const fileList = document.getElementById('fileList');
            fileList.innerHTML = files.map(file => `
                <div class="file-item" data-file="${file.fileName}" onclick="loadFileContent('${file.fileName}')">
                    ${file.fileName}
                </div>
            `).join('');
        }

        

        async function loadFileContent(fileName, fileContent) {
            try {
                // Remove active class from all items
                document.querySelectorAll('.file-item').forEach(item => {
                    item.classList.remove('active');
                });

                // Add active class to clicked item
                document.querySelector(`.file-item[data-file="${fileName}"]`).classList.add('active');

                const response = await fetch(`assets/codeStruct/output_${fileName}.txt`);
                const content = await response.text();
                const converter = new showdown.Converter();
                const htmlContent = converter.makeHtml(content);

                const response2 = await fetch(`assets/codeStruct/sc${fileName}.json`);
                const content2 = await response2.text()+"分";

                document.getElementById('leftPane').innerHTML ="<div class='score'>"+ content2 +"</div><br>"+ htmlContent;

                const codeContent = allFileList[fileName].fileContent;
                const formattedCode = `<pre><code class="language-csharp">${codeContent}</code></pre>`;
                document.getElementById('bottomPane').innerHTML = formattedCode;

                const knMapWindow = document.getElementById('knMap').contentWindow

                const jsonUrl = `assets/codeStruct/kn_${fileName}.json`;
                knMapWindow.postMessage({
                    type: 'loadJson',
                    url: jsonUrl
                }, window.location.origin);
                // Highlight the code using Prism.js
                Prism.highlightAll();


                

            } catch (error) {
                console.error('Error loading file content:', error);
                document.getElementById('contentView').innerText = '无法加载文件内容';
            }
        }
    </script>
    <script src="js4Ai/splitMove1.js"></script>
    <script src="js4Ai/splitMove2.js"></script>
</body>

</html>